import Vue from 'vue';
import Router from 'vue-router';
import Layout from '@/layout';

Vue.use(Router);

const constantRoutes = [
  {
    path: '/',
    name: '首页',
    component: Layout,
    meta: { title: '首页', icon: 'dashboard', affix: true }
  },
  {
    path: '/system',
    name: '系统设置',
    component: Layout,
    meta: { title: '首页', icon: 'dashboard', affix: true },
    children: [
      {
        path: '/system/home',
        name: 'Home',
        component: () => import('@/views/Home.vue'),
        meta: { title: '首页', icon: 'dashboard', affix: true }
      },
      {
        path: '/system/about',
        name: 'about',
        component: () => import('@/views/About.vue'),
        meta: { title: '首页', icon: 'dashboard', affix: true }
      },
      {
        path: '/system/charts',
        name: 'charts',
        component: () => import('@/views/Charts.vue'),
        meta: { title: '图表', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/hello',
    name: '系统设置',
    component: Layout,
    meta: { title: '首页', icon: 'dashboard', affix: true },
    children: [
      {
        path: '/hello/home',
        name: 'Home',
        component: () => import('@/views/Home.vue'),
        meta: { title: '首页', icon: 'dashboard', affix: true }
      },
      {
        path: '/hello/about',
        name: 'about',
        component: () => import('@/views/About.vue'),
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  }
];

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
});

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher;
}

export default router;
